package cn.sumpu.app.coolsk.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import cn.sumpu.app.coolsk.constant.OrderStatus;
import cn.sumpu.app.coolsk.constant.ProductType;
import cn.sumpu.toolkit.common.util.Common;
import cn.sumpu.toolkit.common.util.Encode;

public class Order implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6067897204837452044L;
	private String id;
	private String status;
	private String orderTime;
	private String payFrom;
	private String member;
	private String contactor;
	private String phone;
	private String email;
	private String memo;
	
	private String pname;
	private String type;
	
	private Double totalFee;
	private String company;
	private String stampNum;
	
	private String invoice;
	private String province;
	private String proName;
	private String city;
	private String cityName;
	private String address;
	private String lock;
	
	

	private List<OrderProduct> opList = new ArrayList<OrderProduct>();
	private Date gmtCreated = new Date();
	private Date gmtModified = new Date();
	
	private String pid;
	private Company companyObj;//公司
	private Member memberObj;//会员详细
	
	private String startTime;
	private String endTime;
	private String lockName;

	
	public String getLockName() {
		return lockName;
	}
	public void setLockName(String lockName) {
		this.lockName = lockName;
	}
	public String getLock() {
		return lock;
	}
	public void setLock(String lock) {
		this.lock = lock;
	}
	public String getStartTime() {
		return startTime;
	}
	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}
	public String getEndTime() {
		return endTime;
	}
	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getOrderTime() {
		
		return orderTime;
		
	}
	public String getLdate() {
		if(!Common.empty(opList) && opList.size()>0){
			
			return opList.get(0).getLdate();
		}else{
			return null;
		}
	}
	public void setOrderTime(String orderTime) {
		this.orderTime = orderTime;
	}
	public String getPayFrom() {
		return payFrom;
	}
	public void setPayFrom(String payFrom) {
		this.payFrom = payFrom;
	}
	public String getMember() {
		return member;
	}
	public void setMember(String member) {
		this.member = member;
	}
	public String getContactor() {
		return contactor;
	}
	public void setContactor(String contactor) {
		this.contactor = contactor;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getMemo() {
		return memo;
	}
	public void setMemo(String memo) {
		this.memo = memo;
	}
	public Date getGmtCreated() {
		return gmtCreated;
	}
	public void setGmtCreated(Date gmtCreated) {
		this.gmtCreated = gmtCreated;
	}
	public Date getGmtModified() {
		return gmtModified;
	}
	public void setGmtModified(Date gmtModified) {
		this.gmtModified = gmtModified;
	}
	public List<OrderProduct> getOpList() {
		return opList;
	}
	public void setOpList(List<OrderProduct> opList) {
		this.opList = opList;
	}
	public String getPname() {
		return pname;
	}
	public void setPname(String pname) {
		this.pname = pname;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getEscapePname(){
		if(!Common.empty(pname)){
			return Encode.escape(pname);
		}
		return null;
	}
	public Double getTotalFee() {
		return totalFee;
	}
	public void setTotalFee(Double totalFee) {
		this.totalFee = totalFee;
	}
	public String getPid() {
		return pid;
	}
	public void setPid(String pid) {
		this.pid = pid;
	}
	public String getCompany() {
		return company;
	}
	public void setCompany(String company) {
		this.company = company;
	}
	public String getStampNum() {
		return stampNum;
	}
	public void setStampNum(String stampNum) {
		this.stampNum = stampNum;
	}
	public Company getCompanyObj() {
		return companyObj;
	}
	public void setCompanyObj(Company companyObj) {
		this.companyObj = companyObj;
	}
	public Member getMemberObj() {
		return memberObj;
	}
	public void setMemberObj(Member memberObj) {
		this.memberObj = memberObj;
	}
	
	
	public String getInvoice() {
		return invoice;
	}
	public void setInvoice(String invoice) {
		this.invoice = invoice;
	}
	public String getProvince() {
		return province;
	}
	public void setProvince(String province) {
		this.province = province;
	}
	public String getProName() {
		return proName;
	}
	public void setProName(String proName) {
		this.proName = proName;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	public String getCityName() {
		return cityName;
	}
	public void setCityName(String cityName) {
		this.cityName = cityName;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	/**
	 * 
	 * @return 会员昵称
	 */
	public String getMemberName(){
		if(!Common.empty(memberObj)){
			return memberObj.getNickname();
		}else{
			return null;
		}
		
	}
	public String getStatusName(){
		String statusName=null;
		if(!Common.empty(status)){
			if(status.equals(OrderStatus.BILLED.getValue())){
				statusName="已出票";
			}else if(status.equals(OrderStatus.CANCEL.getValue())){
				statusName="已取消";
			}else if(status.equals(OrderStatus.FINISHED.getValue())){
				statusName="已完成";
			}else if(status.equals(OrderStatus.PAIDED.getValue())){
				statusName="已出票";
			}else if(status.equals(OrderStatus.TOPAID.getValue())){
				statusName="待支付";
			}
			return statusName;
		}else{
			return null;
		}
		
	}
	
	public String getOrderDetail(){
		if(!Common.empty(opList) && opList.size()>0){
			String detail="";
			for (int i = 0; i < opList.size(); i++) {
				OrderProduct op=opList.get(i);
				if(!type.equals(ProductType.TICKET.getValue())){
					detail+=op.getPname()+"<br>";
				}else{
					if(i==0){
						detail="成人票"+op.getAmount()+"张<br>";
					}else{
						detail+="儿童票"+op.getAmount()+"张";
					}
					
				}
			}
			return detail;
		}else{
			return null;
		}
	}
	
	public Integer getTotalAmount(){
		int sum=0;
		if(!Common.empty(opList) && opList.size()>0){
			for (int i = 0; i < opList.size(); i++) {
				OrderProduct op=opList.get(i);
				sum+=op.getAmount();
			}
		}
		return sum;
	}
}
